package com.ruoyi.web.controller.zhuangxiucontroller.shopController;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderAfterSale;
import com.ruoyi.system.service.zhaungxiuservice.shopService.OrderAfterSaleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后管理Controller
 * 
 * @author 张少丛
 * @date 2020-11-05
 */
@RestController
@RequestMapping("/shopping/afterSale")
public class OrderAfterSaleController extends BaseController
{
    @Autowired
    private OrderAfterSaleService orderAfterSaleService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询售后管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:afterSale:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderAfterSale orderAfterSale)
    {
        startPage();
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        List<OrderAfterSale> list = orderAfterSaleService.selectOrderAfterSaleList(orderAfterSale,userId);
        return getDataTable(list);
    }

    /**
     * 导出售后管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:afterSale:export')")
    @Log(title = "售后管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderAfterSale orderAfterSale)
    {
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        List<OrderAfterSale> list = orderAfterSaleService.selectOrderAfterSaleList(orderAfterSale,userId);
        ExcelUtil<OrderAfterSale> util = new ExcelUtil<OrderAfterSale>(OrderAfterSale.class);
        return util.exportExcel(list, "afterSale");
    }

    /**
     * 获取售后管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:afterSale:query')")
    @GetMapping(value = "/{afterSaleId}")
    public AjaxResult getInfo(@PathVariable("afterSaleId") Long afterSaleId)
    {
        return AjaxResult.success(orderAfterSaleService.selectOrderAfterSaleById(afterSaleId));
    }

    /**
     * 新增售后管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:afterSale:add')")
    @Log(title = "售后管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderAfterSale orderAfterSale)
    {
        return toAjax(orderAfterSaleService.insertOrderAfterSale(orderAfterSale));
    }

    /**
     * 修改售后管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:afterSale:edit')")
    @Log(title = "售后管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderAfterSale orderAfterSale)
    {
        return toAjax(orderAfterSaleService.updateOrderAfterSale(orderAfterSale));
    }

    /**
     * 删除售后管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:afterSale:remove')")
    @Log(title = "售后管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{afterSaleIds}")
    public AjaxResult remove(@PathVariable Long[] afterSaleIds)
    {
        return toAjax(orderAfterSaleService.deleteOrderAfterSaleByIds(afterSaleIds));
    }

    /**
     * 确认退款操作
     */
    @PreAuthorize("@ss.hasPermi('shopping:afterSale:edit')")
    @Log(title = "售后管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRefund")
    public AjaxResult updateRefund(@RequestBody OrderAfterSale orderAfterSale)
    {
        return toAjax(orderAfterSaleService.updateOrderAfterSale(orderAfterSale));
    }
}
